package xyz.yinpeng.demo.service;

import feign.hystrix.FallbackFactory;
import lombok.Data;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(value = "provider-service", fallbackFactory = ProviderFeignHystrixFallbackFactory.class)
public interface ProviderFeignService {

    @RequestMapping(value = "/provider/test", method = RequestMethod.POST)
    String sayHello(SayHelloReq params);

    @Data
    class SayHelloReq {
        private String name;
    }

}

@Component
class ProviderFeignHystrixFallbackFactory implements FallbackFactory<ProviderFeignService> {

    @Override
    public ProviderFeignService create(Throwable throwable) {
        return new ProviderFeignService() {
            @Override
            public String sayHello(SayHelloReq params) {
                return "请稍后再试";
            }
        };
    }
}
